const express = require("express");


const app = express();



const port = 3333;


app.use(
  express.urlencoded({
    extended: true,
  })
);

// 加载CORS模块
const cors = require("cors");

// 使用CORS中间件
app.use(
  cors({
    origin: ["http://localhost:8080", "http://127.0.0.1:8080"],
  })
);
// async;
app.use(express.json({limit :"2100000kb"}));







const circle = require("./router/circle");
const login = require("./router/login.js");
const register = require("./router/register");
const category = require("./router/category.js");
// const index = require("./router/index.js");
const list = require("./router/list.js");
const show = require("./router/show.js");
const me = require("./router/me.js");
const select = require("./router/select.js");
const content = require("./router/content");





app.use("/select", select);
app.use("/login", login);
app.use("/register", register);
app.use("/category", category);
// app.use("/index", index);
app.use("/list", list);
app.use("/show", show);
app.use("/me", me);
app.use("/circle", circle);
app.use('/content',content);
//4.引入自定义的用户路由器模块
const userRouter = require("./router/user.js");
//5.使用路由app.use（路径前缀，路由器名字）
app.use("/user", userRouter);

const loginRouter = require("./router/loginrouter");
app.use("/loginhou", loginRouter);

const testname = require("./router/testname.js");
const uid = require("./router/uid.js");
app.use("/testname", testname);
app.use("/uid", uid);

//添加错误处理中间件，拦截所有的错误
app.use((err, req, res, next) => {
  //err 传递过来的错误
  console.log(err);
  //响应内部错误
  res.send({ code: 500, msg: "服务器内部错误" });
});


app.listen(port, () => {
  console.log("已成功监听端口:" + port);
});